package appx.craft.droid.uc;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import appx.craft.droid.R;
import appx.craft.droid.bean.TimeZoneBean;
import appx.craft.droid.utils.Utility;

public class TimeListAdapter extends BaseAdapter {
	
	private static final String TAG = TimeListAdapter.class.getCanonicalName();
	
	Context mContext;
	/** The content mess array list. */
    ArrayList<TimeZoneBean> arrayList$Message;
	
    /** The m layout inflater. */
    LayoutInflater mLayoutInflater;
    
    /**
     * The Class ViewHolder.
     */
    static class ViewHolder {
    	
           TextView txtView$Title;
           TextView txtView$subTitle;
           TextView txtView$Duration;
           
           TextView txtView$number;
           ImageView imgview$location;
    }
    
    
	public TimeListAdapter(Context mContext){
		this.mContext = mContext;
		arrayList$Message = new ArrayList<TimeZoneBean>();
		mLayoutInflater = LayoutInflater.from(mContext);
	}
	
	public void addMoreItems(ArrayList<TimeZoneBean> mArrayListTimeZone){
		
		 if(mArrayListTimeZone == null)
         return;
		 
         if(!arrayList$Message.isEmpty()){
        	 arrayList$Message.clear();
         }
          for(TimeZoneBean mBeanofContent : mArrayListTimeZone){
        	  arrayList$Message.add(mBeanofContent);
         }
          
         notifyDataSetChanged();
		
	}
	/**
     * Removes the all message .
     */
    public void removeAllIteams(){
            
            if(arrayList$Message != null && arrayList$Message.size() > 0)
            {
            		arrayList$Message.clear();
                    notifyDataSetChanged();
                    
            }
    }
	
    public void removeItemAtPosition(int position){
    	
    	  if(arrayList$Message != null && arrayList$Message.size() > 0)
          {
          		arrayList$Message.remove(position);
          		notifyDataSetChanged();
                  
          }
    }
	@Override
	public int getCount() {
		return  arrayList$Message.size();
	}

	@Override
	public Object getItem(int position) {
		return arrayList$Message.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 ViewHolder mCatchView;
         if(convertView == null){
        	 convertView = mLayoutInflater.inflate(R.layout.item_message_content,null,false);
        	 mCatchView = new ViewHolder();
        	 
        	 mCatchView.txtView$Title =(TextView) convertView.findViewById(R.id.textview_title);
        	 mCatchView.txtView$subTitle = (TextView)convertView.findViewById(R.id.textview_subtitle);
        	 mCatchView.txtView$Duration = (TextView)convertView.findViewById(R.id.textview_timezone);
        	 mCatchView.txtView$number = (TextView)convertView.findViewById(R.id.textView_number);
        	 mCatchView.imgview$location = (ImageView)convertView.findViewById(R.id.imagview_bubble);
        	 
        	 convertView.setTag(mCatchView);
        	 
         }else{
        	 
        	   mCatchView = (ViewHolder)convertView.getTag();
         }
         
         if(arrayList$Message.size() > 0){
        	 
        	 if(arrayList$Message.get(position).getIntimageID() == 0){
        		 mCatchView.imgview$location.setVisibility(View.GONE);
        		 mCatchView.imgview$location.setBackgroundDrawable(null);	 
        	 }else{
        		 mCatchView.imgview$location.setVisibility(View.VISIBLE);
        		 mCatchView.imgview$location.setBackgroundDrawable(mContext.getResources().getDrawable(arrayList$Message.get(position).getIntimageID()));
        	 }
        	 
        	 if(!arrayList$Message.get(position).getStrNumber().equalsIgnoreCase("")){
        		 
        		 mCatchView.txtView$number.setVisibility(View.VISIBLE);
        		 mCatchView.txtView$number.setText("3");
        	 }else{
        		 mCatchView.txtView$number.setVisibility(View.INVISIBLE);
        	 }
        	 
    		 mCatchView.txtView$Title.setText(arrayList$Message.get(position).getStrTitle());
             mCatchView.txtView$subTitle.setText(arrayList$Message.get(position).getStrsubTitle());
             mCatchView.txtView$Duration.setText(Utility.getYouTimeDuration(arrayList$Message.get(position).getStrTimeDuration()));
//             mCatchView.txtView$Duration.setText(arrayList$Message.get(position).getStr$TimeDuration());
             
         }
         
         
		return convertView;
	}
	
	

}
